package com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.biz.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.biz.service.KpiCateService;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.biz.service.KpiCoreDataService;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.biz.service.KpiDeptService;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.biz.service.KpiDoctorService;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.biz.service.KpiGradeService;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.biz.service.KpiMedicalOrgService;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.biz.service.KpiSocService;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.KpiCateDTO;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.KpiConditionDTO;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.KpiDeptDTO;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.KpiDoctorDTO;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.KpiGradeDTO;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.KpiMedicalOrgDTO;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.KpiSociationDTO;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.PaginationQueryDTO;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.util.CommonUtil;

@Component("kpiCoreDataService")
public class KpiCoreDataServiceImpl implements KpiCoreDataService {

	@Resource(name = "kpiSocService")
	private KpiSocService kpiSocService;

	@Resource(name = "kpiGradeService")
	private KpiGradeService kpiGradeService;

	@Resource(name = "kpiCateService")
	private KpiCateService kpiCateService;

	@Resource(name = "kpiMedicalOrgService")
	private KpiMedicalOrgService kpiMedicalOrgService;

	@Resource(name = "kpiDeptService")
	private KpiDeptService kpiDeptService;

	@Resource(name = "kpiDoctorService")
	private KpiDoctorService kpiDoctorService;

	/**
	 * 查询指标数据-统筹区维度
	 * 
	 * @param condition
	 * @return
	 */
	@Override
	public List<KpiSociationDTO> queryKpiBySoc(KpiConditionDTO condition) {
		// TODO Auto-generated method stub
		if (condition != null) {
			return kpiSocService.queryKpi(condition);
		}
		return null;
	}
	
	/**
	 * 查询指标数据-统筹区维度
	 * 
	 * @param condition
	 * @return
	 */
	@Override
	public Object querySingleKpiBySoc(KpiConditionDTO condition) {
		// TODO Auto-generated method stub
		if (condition != null) {
			return kpiSocService.querySingleKpi(condition);
		}
		return null;
	}

	/**
	 * 查询指标数据-医院等级维度
	 * 
	 * @param condition
	 * @return
	 */
	@Override
	public List<KpiGradeDTO> queryKpiByGrade(KpiConditionDTO condition) {
		// TODO Auto-generated method stub
		if (condition != null) {
			return kpiGradeService.queryKpi(condition);
		}
		return null;
	}
	

	/**
	 * 查询指标数据-医院类型维度
	 * 
	 * @param condition
	 * @return
	 */
	@Override
	public List<KpiCateDTO> queryKpiByCate(KpiConditionDTO condition) {
		// TODO Auto-generated method stub
		if (condition != null) {
			return kpiCateService.queryKpi(condition);
		}
		return null;
	}

	/**
	 * 查询指标数据-医院维度
	 * 
	 * @param condition
	 * @return
	 */
	@Override
	public List<KpiMedicalOrgDTO> queryKpiByOrg(KpiConditionDTO condition) {
		// TODO Auto-generated method stub
		if (condition != null) {
			return kpiMedicalOrgService.queryKpi(condition);
		}
		return null;
	}
	
	/**
	 * 查询指标数据-医院维度单一结果
	 * 
	 * @param condition
	 * @return
	 */
	@Override
	public Object querySingleKpiByOrg(KpiConditionDTO condition) {
		// TODO Auto-generated method stub
		return kpiMedicalOrgService.querySingleKpi(condition);
	}

	/**
	 * 查询指标数据-科室维度
	 * 
	 * @param condition
	 * @return
	 */
	@Override
	public List<KpiDeptDTO> queryKpiByDept(KpiConditionDTO condition) {
		// TODO Auto-generated method stub
		if (condition != null) {
			return kpiDeptService.queryKpi(condition);
		}
		return null;
	}

	/**
	 * 查询指标数据-医生维度
	 * 
	 * @param condition
	 * @return
	 */
	@Override
	public List<KpiDoctorDTO> queryKpiByDoctor(KpiConditionDTO condition) {
		// TODO Auto-generated method stub
		if (condition != null) {
			return kpiDoctorService.queryKpi(condition);
		}
		return null;
	}

	/**
	 * 查询指标数据-指标分析器-医院维度
	 * 
	 * @param condition
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<KpiMedicalOrgDTO> queryKpiAnalyzeByOrg(KpiConditionDTO condition) throws Exception {
		// TODO Auto-generated method stub
		List<KpiMedicalOrgDTO> returnList = new ArrayList<KpiMedicalOrgDTO>();

		if (condition != null) {
			// 参数转换
			PaginationQueryDTO paginationCon = new PaginationQueryDTO();
			CommonUtil.propertyCopy(paginationCon, condition.getPagination());
			Map<String, Object> param = new HashMap<String, Object>();
			CommonUtil.propertyCopyForMap(param, condition);
			paginationCon.setParam(param);
			returnList = kpiMedicalOrgService.queryKpiAnalyze(paginationCon);
		}
		return returnList;
	}

	/**
	 * 查询指标数据行数-指标分析器-医院维度
	 * 
	 * @param condition
	 * @return
	 */
	@Override
	public int queryKpiAnalyzeCountByOrg(KpiConditionDTO condition) {
		// TODO Auto-generated method stub
		int count = 0;
		if (condition != null) {
			count = kpiMedicalOrgService.queryKpiAnalyzeCount(condition);
		}
		return count;
	}

	@Override
	public List<KpiDeptDTO> queryKpiAnalyzeByDept(KpiConditionDTO condition) throws Exception {
		// TODO Auto-generated method stub
		List<KpiDeptDTO> returnList = new ArrayList<KpiDeptDTO>();

		if (condition != null) {
			// 参数转换
			PaginationQueryDTO paginationCon = new PaginationQueryDTO();
			CommonUtil.propertyCopy(paginationCon, condition.getPagination());
			Map<String, Object> param = new HashMap<String, Object>();
			CommonUtil.propertyCopyForMap(param, condition);
			paginationCon.setParam(param);
			returnList = kpiDeptService.queryKpiAnalyze(paginationCon);
		}
		return returnList;
	}

	@Override
	public int queryKpiAnalyzeCountByDept(KpiConditionDTO condition) {
		// TODO Auto-generated method stub
		int count = 0;
		if (condition != null) {
			count = kpiDeptService.queryKpiAnalyzeCount(condition);
		}
		return count;
	}

	@Override
	public List<KpiDoctorDTO> queryKpiAnalyzeByDoctor(KpiConditionDTO condition) throws Exception {
		// TODO Auto-generated method stub
		List<KpiDoctorDTO> returnList = new ArrayList<KpiDoctorDTO>();
		// 参数转换
		if (condition != null) {
			PaginationQueryDTO paginationCon = new PaginationQueryDTO();
			CommonUtil.propertyCopy(paginationCon, condition.getPagination());
			Map<String, Object> param = new HashMap<String, Object>();
			CommonUtil.propertyCopyForMap(param, condition);
			paginationCon.setParam(param);
			returnList = kpiDoctorService.queryKpiAnalyze(paginationCon);
		}
		return returnList;
	}

	@Override
	public int queryKpiAnalyzeCountByDoctor(KpiConditionDTO condition) {
		// TODO Auto-generated method stub
		int count = 0;
		if (condition != null) {
			count = kpiDoctorService.queryKpiAnalyzeCount(condition);
		}
		return count;
	}

}
